package movies.repositoryHibernate;

import java.util.List;
import movies.domain.Role;
import movies.repository.IRoleRepository;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Ann
 */
public class RoleRepository extends HibernateDaoSupport
implements IRoleRepository{

    @Override
    public Role getRoleById(int id) {
         List < Role > roles = getHibernateTemplate().
             findByNamedQuery("GetRoleById", id);

        if (roles.size() == 1) {
            return roles.get(0);
        } else {
            return null;
        }
    }

    @Override
    public Role getRoleByName(String name) {
        List < Role > roles = getHibernateTemplate().
             findByNamedQuery("GetRoleByName", name);

        if (roles.size() == 1) {
            return roles.get(0);
        } else {
            return null;
        }
    }

    @Override
    public List<Role> getAllRoles() {
        List < Role > roles = getHibernateTemplate().
             findByNamedQuery("GetAllRoles");

        if (roles.size() > 0) {
            return roles;
        } else {
            return null;
        }
    }

}
